<template>
    <div>
        <slot></slot>
    </div>
</template>

<script>
export default {
    provide() {
        return {
            model: this.model,
            rules: this.rules,
        };
    },
    props: {
        model: Object,
        rules: Object,
    },
    methods: {
        validate(cb) {
            // console.log('this.$children', this.$children);

            const resultArr = this.$children.map((item) =>
                item.validate(this.model[item.prop])
            );

            // console.log('resultArr', resultArr);

            Promise.all(resultArr)
                .then(() => {
                    cb(true);
                })
                .catch(() => {
                    cb(false);
                });
        },
    },
};
</script>

<style lang="scss" scoped></style>
